package org.hwadee.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.hwadee.entity.Communication;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommunicationMapper {

    @Select("select * from communication where receiver=#{userId} order by lastMessageTime desc")
    List<Communication> listCommunicationByTime(Integer userId);

    @Select("select * from communication where sender=#{senderId} and receiver=#{receiverId}")
    Communication selectCommunicationBySenderAndReceiverId(@Param("senderId") Integer senderId, @Param("receiverId") Integer receiverId);

    @Insert("insert into communication (sender, receiver, lastMessageTime) values (#{sender}, #{receiver}, #{lastMessageTime})")
    void insertCommunication(Communication communication);
}
